{
 "cells": [
  {
   "cell_type": "code",
   "execution_count": 32,
   "metadata": {},
   "outputs": [],
   "source": [
    "from keras.layers import Input, concatenate, Embedding\n",
    "from keras.layers.core import Dense, Activation, Flatten\n",
    "from keras.models import Model\n",
    "from keras.utils import plot_model"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 33,
   "metadata": {},
   "outputs": [],
   "source": [
    "def model():\n",
    "    input1 = Input(shape=(114,))\n",
    "    input2 = Input(shape=(10,))\n",
    "    \n",
    "    dense1 = Dense(64)(input1)\n",
    "    active1 = Activation('relu')(dense1)\n",
    "    embedding = Embedding(18375, 512, input_length=(10,))(input2)\n",
    "    flatten = Flatten()(embedding)\n",
    "    \n",
    "    merge = concatenate([active1, flatten])\n",
    "    \n",
    "    dense2 = Dense(4096)(merge)\n",
    "    active2 = Activation('relu')(dense2)\n",
    "    dense3 = Dense(2048)(active2)\n",
    "    active3 = Activation('relu')(dense3)\n",
    "    dense4 = Dense(2048)(active3)\n",
    "    active4 = Activation('relu')(dense4)\n",
    "    dense5 = Dense(1024)(active4)\n",
    "    active5 = Activation('relu')(dense5)\n",
    "    dense6 = Dense(1024)(active5)\n",
    "    active6 = Activation('relu')(dense6)\n",
    "    dense7 = Dense(512)(active6)\n",
    "    active7 = Activation('relu')(dense7)\n",
    "    dense8 = Dense(512)(active7)\n",
    "    active8 = Activation('relu')(dense8)\n",
    "    dense9 = Dense(256)(active8)\n",
    "    active9 = Activation('relu')(dense9)\n",
    "    dense10 = Dense(1)(active9)\n",
    "    active10 = Activation('sigmoid')(dense10)\n",
    "    \n",
    "    model = Model(inputs=[input1,input2], outputs=active10)\n",
    "    \n",
    "    return model"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 34,
   "metadata": {},
   "outputs": [],
   "source": [
    "model = model()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 35,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "__________________________________________________________________________________________________\n",
      "Layer (type)                    Output Shape         Param #     Connected to                     \n",
      "==================================================================================================\n",
      "input_21 (InputLayer)           (None, 114)          0                                            \n",
      "__________________________________________________________________________________________________\n",
      "input_22 (InputLayer)           (None, 10)           0                                            \n",
      "__________________________________________________________________________________________________\n",
      "dense_40 (Dense)                (None, 64)           7360        input_21[0][0]                   \n",
      "__________________________________________________________________________________________________\n",
      "embedding_11 (Embedding)        (None, 10, 512)      9408000     input_22[0][0]                   \n",
      "__________________________________________________________________________________________________\n",
      "activation_35 (Activation)      (None, 64)           0           dense_40[0][0]                   \n",
      "__________________________________________________________________________________________________\n",
      "flatten_11 (Flatten)            (None, 5120)         0           embedding_11[0][0]               \n",
      "__________________________________________________________________________________________________\n",
      "concatenate_9 (Concatenate)     (None, 5184)         0           activation_35[0][0]              \n",
      "                                                                 flatten_11[0][0]                 \n",
      "__________________________________________________________________________________________________\n",
      "dense_41 (Dense)                (None, 4096)         21237760    concatenate_9[0][0]              \n",
      "__________________________________________________________________________________________________\n",
      "activation_36 (Activation)      (None, 4096)         0           dense_41[0][0]                   \n",
      "__________________________________________________________________________________________________\n",
      "dense_42 (Dense)                (None, 2048)         8390656     activation_36[0][0]              \n",
      "__________________________________________________________________________________________________\n",
      "activation_37 (Activation)      (None, 2048)         0           dense_42[0][0]                   \n",
      "__________________________________________________________________________________________________\n",
      "dense_43 (Dense)                (None, 2048)         4196352     activation_37[0][0]              \n",
      "__________________________________________________________________________________________________\n",
      "activation_38 (Activation)      (None, 2048)         0           dense_43[0][0]                   \n",
      "__________________________________________________________________________________________________\n",
      "dense_44 (Dense)                (None, 1024)         2098176     activation_38[0][0]              \n",
      "__________________________________________________________________________________________________\n",
      "activation_39 (Activation)      (None, 1024)         0           dense_44[0][0]                   \n",
      "__________________________________________________________________________________________________\n",
      "dense_45 (Dense)                (None, 1024)         1049600     activation_39[0][0]              \n",
      "__________________________________________________________________________________________________\n",
      "activation_40 (Activation)      (None, 1024)         0           dense_45[0][0]                   \n",
      "__________________________________________________________________________________________________\n",
      "dense_46 (Dense)                (None, 512)          524800      activation_40[0][0]              \n",
      "__________________________________________________________________________________________________\n",
      "activation_41 (Activation)      (None, 512)          0           dense_46[0][0]                   \n",
      "__________________________________________________________________________________________________\n",
      "dense_47 (Dense)                (None, 512)          262656      activation_41[0][0]              \n",
      "__________________________________________________________________________________________________\n",
      "activation_42 (Activation)      (None, 512)          0           dense_47[0][0]                   \n",
      "__________________________________________________________________________________________________\n",
      "dense_48 (Dense)                (None, 256)          131328      activation_42[0][0]              \n",
      "__________________________________________________________________________________________________\n",
      "activation_43 (Activation)      (None, 256)          0           dense_48[0][0]                   \n",
      "__________________________________________________________________________________________________\n",
      "dense_49 (Dense)                (None, 1)            257         activation_43[0][0]              \n",
      "__________________________________________________________________________________________________\n",
      "activation_44 (Activation)      (None, 1)            0           dense_49[0][0]                   \n",
      "==================================================================================================\n",
      "Total params: 47,306,945\n",
      "Trainable params: 47,306,945\n",
      "Non-trainable params: 0\n",
      "__________________________________________________________________________________________________\n"
     ]
    }
   ],
   "source": [
    "model.summary()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 36,
   "metadata": {},
   "outputs": [],
   "source": [
    "plot_model(model, to_file='model1.png',show_shapes=True)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": []
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.6.8"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 2
}
